<script src="components/com_questionpage/public/uploadlib/jquery.min.js" type="text/javascript"></script>
<script src="components/com_questionpage/public/uploadlib/jquery.uploadify.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="components/com_frmessage/public/uploadlib/uploadify.css"/>

<script type="text/javascript" src="../media/system/js/jQuery.vietvang.validate.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$('#adminForm').validate({
			});
		});
</script>

<form action="index.php?option=com_questionpage" method="post" class="adminform" id="adminForm" name="adminForm" enctype="multipart/form-data" >
   <table class="tbl-ques" border=0>
    	<tr>
    		<td style="text-align: right;font-size: 1.091em;padding-right:5px;width:30%;"><label>ID</label></td>
    		<td style="width: 30%;font-size: 1.091em"> 
                <label><?php echo HelperBG::getIDAuto('pagq','PAGQ_CODE');?></label>
                <input name="jform[PAGQ_CODE]" type="hidden"  value="<?php echo HelperBG::getIDAuto('pagq','PAGQ_CODE'); ?>" />
            </td>
    		<td style="width: 50%;"><span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;text-align: left;">※印は入力必須項目です。</span></td>
    	</tr>
    	<tr>
    		<td style="text-align: right;font-size: 1.091em;padding-right:5px;" ><label>ページ名<span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;">※</span></label>	</td>
    		<td colspan="2"><input type="text" id="jform[PAGQ_TITLE]" name="jform[PAGQ_TITLE]" class="inputbox big" size="30" /></td>
    	</tr>
       
        <tr>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;"> アンケート名<span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;">※</span></td>
            <td colspan="2" >
                <select class="big" name="jform[PAGQ_SERQ_CODE]" id="jform[PAGQ_SERQ_CODE]">
                    <option value="0">アンケート名</option>
                    <?php foreach($this->questionare as $value){ ?>

            	       <option value="<?php echo $value->SERQ_CODE; ?>" ><?php echo $value->SERQ_TITLE; ?></option>
                    <?php }?>
                </select>
       	    </td>
        </tr>
    	<tr>
    		<td style="text-align: right;font-size: 1.091em;padding-right:5px;">
                <label>ページ説明</label>	
            </td>
    		<td colspan="2"> <textarea cols="33" rows="6" id="jform[PAGQ_DESCRIPTION]" name="jform[PAGQ_DESCRIPTION]"></textarea ></td>
    	</tr>
        <tr>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;">画像</td>
            <td colspan="2">
                <input type="file" id="jformPAGQ_IMG"  name="jformPAGQ_IMG" class="big" size="30" />
                <input type="hidden" name="jform[PAGQ_IMG_NEW]" id="value_PAGQ_IMG" value="" />
            </td>
            
        </tr>
        <tr>
            <td></td>
            <td id="preview" colspan="2"><img class="img_questionare_add fl-left" id="showimg"/></td>
        </tr>
        <!-- 
         <tr>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;"><label>公開/非公開</label></td>
            <td colspan="2">
                <select id="jform[PAGQ_PUBLISHED]" name="jform[PAGQ_PUBLISHED]" class="big" >
                    <option value="1">公開 </option>
                    <option value="0">非公開 </option>
                </select>
            </td>
        </tr>
         -->
    </table>
  <div>
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
  </div>
</form>

<?php $timestamp = time();?>
<script>

    
  
    $(function() {
        $('#jformPAGQ_IMG').uploadify({
            'formData'     : {
    			'timestamp' : '<?php echo $timestamp;?>',
    			'token'     : '<?php echo md5('unique_salt' . $timestamp);?>',
                'PAGQ_CODE' : '<?php echo HelperBG::getIDAuto('pagq','PAGQ_CODE'); ?>'
    		},
            'multi'    : false,
            'removeTimeout' : 1,
            'fileSizeLimit' : '26MB',
            'buttonText' : '画像を選択してください。',
            'width'    : 170,
            'swf'      : 'components/com_questionpage/public/uploadlib/uploadify.swf',
            'uploader' : 'components/com_questionpage/public/uploadlib/uploadify.php',           
            'onUploadSuccess' : function(file, data, response) {
                
                /* show image */
                $('#preview').html(
                '<img style="width: 100px; height: 100px;" id="showimg" src="uploads/images/com_questionpage/'+data+'" />');
                $('#value_PAGQ_IMG').val(data);
            }
            // Put your options here
        });
    });
    
    /* remove anh chon khi click cancel */
    Joomla.submitbutton = function(task){
        if(task == 'cancel'){
                var image_name_old = jq('#value_PAGQ_IMG').val();
                if(image_name_old != ''){
                    jq.ajax({
                      url: 'index.php?option=com_questionpage&task=removeImage'+'&image_name='+image_name_old,
                      context: document.body
                    }).done(function(data ) {
                        
                    });
                }
        }
           
        Joomla.submitform(task, document.getElementById('adminForm'));
           
     }
     
</script>